package com.lw.chat.view.chat;

import cn.hutool.core.util.StrUtil;
import de.saxsys.mvvmfx.FxmlView;
import de.saxsys.mvvmfx.InjectViewModel;
import javafx.beans.binding.Bindings;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.VBox;
import javafx.scene.shape.Polygon;

import java.net.URL;
import java.util.ResourceBundle;

/**
 * @description:
 * @className: ChatController
 * @author: liwen
 * @date: 2020/12/13 13:34
 */
public class MessageBoxMeView implements FxmlView<MessageBoxViewMeModel>, Initializable {


    @FXML
    private ImageView avatarImageView;

    @FXML
    private Label msgLabel;
    @FXML
    private ImageView msgImageView;

    @FXML
    private Polygon polygon;



    @InjectViewModel
    private MessageBoxViewMeModel messageBoxViewMeModel;

    @Override
    public void initialize(URL url, ResourceBundle resourceBundle) {


        avatarImageView.imageProperty().bind(Bindings.createObjectBinding(
                () ->StrUtil.isEmpty(messageBoxViewMeModel.avatarUriProperty().getValue()) ?null: new Image(messageBoxViewMeModel.avatarUriProperty().getValue()), messageBoxViewMeModel.avatarUriProperty())
        );
        msgImageView.imageProperty().bind(Bindings.createObjectBinding(
                () -> StrUtil.isEmpty(messageBoxViewMeModel.msgImageUriProperty().getValue()) ?null:new Image(messageBoxViewMeModel.msgImageUriProperty().getValue()), messageBoxViewMeModel.msgImageUriProperty())
        );
        msgLabel.textProperty().bind(messageBoxViewMeModel.messageProperty());

        msgImageView.visibleProperty().bind(messageBoxViewMeModel.msgImageUriProperty().isNotNull());
        msgImageView.managedProperty().bind(msgImageView.visibleProperty());

    }


}
